package com.example.day_20.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.day_20.R;
import com.example.day_20.bean.InFoBean;

import java.util.ArrayList;
import java.util.List;

public class RlvCollectAdapter extends RecyclerView.Adapter<RlvCollectAdapter.ViewHolder> {

    private Context context;
    private List<InFoBean.DataBean.DatasBean> datas = new ArrayList<>();

    public RlvCollectAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<InFoBean.DataBean.DatasBean> datas) {
        this.datas = datas;
    }

    @NonNull
    @Override
    public RlvCollectAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_home_one, viewGroup, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RlvCollectAdapter.ViewHolder viewHolder, int i) {
        InFoBean.DataBean.DatasBean datasBean = datas.get(i);
        viewHolder.tv_one.setText(datasBean.getTitle());
        Glide.with(context).load(datasBean.getEnvelopePic()).into(viewHolder.iv_one);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_one;
        TextView tv_one;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_one = itemView.findViewById(R.id.iv_one);
            tv_one = itemView.findViewById(R.id.tv_one);
        }
    }
}
